package com.wcy.controller.perm;

import com.wcy.annotation.aop.PreAuth;
import com.wcy.entity.Role;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.perm.FeignRoleService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class RoleController {
    @Resource
    private FeignRoleService feignRoleService;


    @GetMapping("role/page")
    public ResponseEntity<PageData<Role>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                  @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.ok(new PageData<>(Role.class, Objects.requireNonNull(feignRoleService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("role/add", "role/update", "role/delete"), ColumnConstructor.create()));
    }

    @GetMapping("role/list")
    public ResponseEntity<List<Role>> getList(){
        return feignRoleService.getList();
    }


    @PostMapping("role/add")
    public ResponseEntity<Void> add(@RequestBody Role role){
        return feignRoleService.add(role);
    }


    @PutMapping("role/update")
    public ResponseEntity<Void> update(@RequestBody Role role){
        return feignRoleService.update(role);
    }


    @DeleteMapping("role/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id){
        return feignRoleService.delete(id);
    }
}
